package com.qf.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zjw
 * @description
 * @date 2021/10/14 11:23
 */
@RestController
public class UserController {

    @PostMapping("/do-login")
    public String login(String username,String password){
        Subject subject = SecurityUtils.getSubject();

        subject.login(new UsernamePasswordToken(username,password));

        return "login success!";
    }

    @GetMapping("/logout")
    public String logout(){
        Subject subject = SecurityUtils.getSubject();
        subject.logout();
        return "ok!";
    }


}
